package org.example.direct;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import org.example.utils.RabbitMqUtils;

/**
 * @author zfj
 * @date 2022/4/24 -16:19
 */
public class ReceiveLogsDirect02 {
	private static final String EXCHANGE_NAME = "direct_logs";

	public static void main(String[] argv) throws Exception {
		Channel channel = RabbitMqUtils.getChannel();
		//声明一个交换机
		channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.DIRECT);
		//声明队列
		String queueName = "disk";
		channel.queueDeclare(queueName, false, false, false, null);
		channel.queueBind(queueName, EXCHANGE_NAME, "error");
		DeliverCallback deliverCallback= (consumerTag, delivery) -> {
			String message = new String(delivery.getBody(), "UTF-8");
			System.out.println("ReceiveLogsDirect02控制台打印接收到的消息"+message);
		};
		channel.basicConsume(queueName,true,deliverCallback,consumerTag -> { });

	}
}
